package com.mock.ems.controller.operation;

import com.jfinal.aop.Before;
import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import com.jfinal.plugin.activerecord.tx.Tx;
import com.mock.ems.common.JsonResult;

/**
 * Created by MOCK on 2017/7/11.
 */

public class DataTestController extends Controller {

    public void index() {
        renderJsp("/page/operation/data_test.jsp");
    }

    @Before(Tx.class)
    public void delete() {
        String phone = getPara("phone");
        JsonResult result = new JsonResult();
        Record record = Db.findFirst("select * from user where login_account = ? ",phone);
        if (null == record) {
            renderJson(result.status("-1").show("删除失败，用户不存在！"));
            return;
        }
        Long userId = record.getLong("id");
        Db.update("delete from user where login_account = ? ",phone);
        Db.update("delete from user_account where user_id = ? ",userId);
        Db.update("delete from user_address where user_id = ? ",userId);
        Db.update("delete from user_auth_record where user_id = ?",userId);
        Db.update("delete from user_bank_card where user_id = ?",userId);
        Db.update("delete from user_feedback where user_id = ?",userId);
        Db.update("delete from user_funds_record where user_id = ?",userId);
        Db.update("delete from user_recharge_record where user_id = ?",userId);
        Db.update("delete from user_relation where user_id = ? or related_id = ? ",userId,userId);
        Db.update("delete from user_score_record where user_id = ? ",userId);
        Db.update("delete from user_withdraw_record where user_id = ? ",userId);
        Db.update("delete from tenant_apply_record where user_id = ?",userId);
        Db.update("delete from property_repair_record where user_id = ? ",userId);

        Db.update("delete from property_notice where publisher_id = ?",userId);
        Db.update("delete from property_delivery_record where user_id = ?",userId);
        Db.update("delete from property_bill_record where user_id = ?",userId);
        Db.update("delete from property_apply_record where user_id = ?",userId);
        Db.update("delete from property_activity_apply_record where user_id = ?",userId);

        Db.update("delete from notice_train where publisher_id = ? ",userId);
        Db.update("delete from notice_system where publisher_id = ? ",userId);

        Db.update("delete from mall_coupon_record where user_id = ?",userId);

        Db.update("delete from chat_relation_group_member where member_id = ?",userId);
        Db.update("delete from chat_relation_group where user_id = ?",userId);
        Db.update("delete from chat_group_member where member_id = ?",userId);
        Db.update("delete from chat_group where owner_id = ?",userId);
        Db.update("delete from chat_friends where user_id = ? or friend_id = ? ",userId,userId);
        Db.update("delete from chat_friend_apply_record where inviter_id = ? or handler_id = ? ",userId,userId);
        Db.update("delete from agent_apply_record where user_id = ?",userId);

        renderJson(result.status("000").show("已经删除掉用户所有的数据"));
    }
}
